package com.zmn.plat.dubbo.impl.part;

import java.util.List;
import java.util.Objects;

import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.plat.common.dto.part.PartSkuRelationDRO;
import com.zmn.plat.dubbo.interfaces.part.PartSkuRelationListRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;
import com.zmn.plat.model.entity.part.PartSkuRelationDTO;
import com.zmn.plat.services.interfaces.part.PartSkuRelationService;

/**
 * The type Part sku relation remote service.
 *
 * @author xiangjunming
 * @since 2019/03/27 10:28:38
 */
@Service(loadbalance = "roundrobin", timeout = 5000, retries = -1, version = DubboConsts.INTERFACE_VERSION)
public class PartSkuRelationListRemoteServiceImpl implements PartSkuRelationListRemoteService {

    private Logger logger = LoggerFactory.getLogger(PartSkuRelationListRemoteServiceImpl.class);

    @Autowired
    private PartSkuRelationService service;

    private static final String TAG = "配件拆分关系 dubbo 接口";

    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<PartSkuRelationDRO>> listByOneSkuIds(List<Integer> oneSkuIds) {
        if (Objects.isNull(oneSkuIds)) {
            logger.error(String.format("[%s]参数:[%s]不能为空", TAG, "oneSkuIds"));
            return ResponseDTO.fail("oneSkuIds不能为空");
        }
        List<PartSkuRelationDTO> dtos = service.listByOneSkuIds(oneSkuIds);
        if (Objects.isNull(dtos)) {
            logger.error(String.format("[%s]参数:[%s]对应的对象不存在", TAG, "oneSkuIds"));
            return ResponseDTO.fail(String.format("[%s]对应的对象不存在", oneSkuIds));
        }
        List<PartSkuRelationDRO> dros = BeanMapper.mapList(dtos, PartSkuRelationDRO.class);
        return ResponseDTO.success(dros, "OK");
    }
}
